/**

 @Name：用户管理
 @Author：xuqipeter
 @Site：http://blog.xuziyu.cn/
    
 */

layui.define(['table', 'layer', 'm-utils', 'form', 'admin', 'view'], function (exports) {
  var $ = layui.$,
    table = layui.table,
    layer = layui.layer,
    admin = layui.admin,
    view = layui.view,
    form = layui.form,
    setter = layui.setter,
    baseUrl = setter.baseUrl,
    ossUrl = setter.ossUrl,
    utils = layui['m-utils'];
  var WithdrawalModel = {
    layerFull: null,
    tableList: null,
    _tableList() {
      return table.render({
        elem: '#tableList',
        url: `${baseUrl}admin/account/getWithdrawList`,
        // toolbar: '#theadToolbar',
        toolbar: true,
        parseData: function (res) {
          return utils.setParseData({
            res,
            data: 'withdrawList'
          })
        },
        cols: [
          [{
              field: 'account_withdraw_id',
              title: 'ID'
            },
            {
              field: 'number',
              title: '用户编号'
            },
            {
              field: 'realname',
              title: '用户姓名',
            },
            {
              field: 'bank',
              title: '银行名'
            },
            {
              field: 'bankcard',
              title: '银行卡号',
              width: 200
            },
            {
              field: 'amount',
              title: '提现金额'
            },

            {
              field: 'created_time',
              title: '提现时间',
              width: 180,
              templet: function (d) {
                if (!d.created_time) return ''
                return utils.formatTime(d.created_time)
              }
            },
            {
              field: 'status',
              title: '提现状态',
              templet: function (d) {
                let text = ''
                switch (d.status) {
                  case 'success':
                    text = '<span class="layui-badge">提现成功</span>'
                    break;
                  case 'failure':
                    text = '<span class="layui-badge layui-bg-green">提现失败</span>'
                    break;
                  case 'created':
                    text = `<span class="layui-badge layui-bg-gray">等待处理</span>`
                    break;
                }
                return text
              }
            },
            {
              field: 'withdraw_time',
              title: '处理时间',
              width: 180,
              templet: function (d) {
                if (!d.withdraw_time || d.withdraw_time == 0) return ''
                return utils.formatTime(d.withdraw_time)
              }
            },
            {
              field: 'note',
              title: '备注'
            },
            {
              title: '操作',
              fixed: 'right',
              width: 160,
              align: 'center',
              toolbar: '#trToolbar'
            }
          ]
        ],
        done: function (d) {
          console.log(d)
          if (d[setter.response.statusName] == setter.response.statusCode.logout) {
            view.exit()
          }
        }
      })
    },
    _doWithdraw({
      fieldData,
      callback
    }) {
      let {
        account_withdraw_id,
        status,
        note
      } = fieldData
      let that = this
      admin.req({
        url: `${baseUrl}admin/account/doWithdraw`,
        method: 'post',
        data: {
          account_withdraw_id,
          status,
          note
        },
        dataType: 'json',
        done: function (res) {
          utils._doneSuccess({
            res,
            layerFull: that.layerFull,
            layTable: that.tableList
          })
          callback && callback(res)
        }
      })
    }
  }

  exports('WithdrawalModel', WithdrawalModel)
})